﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BGCOP.CAVTOP.WINFORMS.frmtlk;
using Telerik.WinControls.UI.Export;
using Telerik.WinControls.UI.Localization;

namespace BGCOP.CAVTOP.WINFORMS
{
    public partial class frmVehiculoEmpleado : Form
    {
        public frmVehiculoEmpleado()
        {
            InitializeComponent();
        }

        private void tEmpleadoVehiculoBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Desea realizar las operaciones pendientes?", Properties.Settings.Default.Titulo,
               MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
            {
                try
                {
                    this.Validate();
                    this.tEmpleadoVehiculoBindingSource.EndEdit();
                    this.tableAdapterManager.UpdateAll(this.masterDBACDataSet);
                    MessageBox.Show("El registro se proceso con exito!", Properties.Settings.Default.Titulo
                                    , MessageBoxButtons.OK);
                }
                catch (Exception ex)
                {
                    
                    MessageBox.Show("Error: " + ex.ToString(), Properties.Settings.Default.Titulo
                                    , MessageBoxButtons.OK ,MessageBoxIcon.Error);
                    
                }
                
            }
        }

        private void frmVehiculoEmpleado_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'masterDBACDataSet.TVehiculo' table. You can move, or remove it, as needed.
            this.tVehiculoTableAdapter.Fill(this.masterDBACDataSet.TVehiculo);
            // TODO: This line of code loads data into the 'masterDBACDataSet.TEmpleado' table. You can move, or remove it, as needed.
            this.tEmpleadoTableAdapter.Fill(this.masterDBACDataSet.TEmpleado);
            // TODO: This line of code loads data into the 'masterDBACDataSet.TEmpleadoVehiculo' table. You can move, or remove it, as needed.
            this.tEmpleadoVehiculoTableAdapter.Fill(this.masterDBACDataSet.TEmpleadoVehiculo);
            RadGridLocalizationProvider.CurrentProvider = new MyEnglishRadGridLocalizationProvider();
        }

        private void radGridView1_CellBeginEdit(object sender, Telerik.WinControls.UI.GridViewCellCancelEventArgs e)
        {
            try
            {
                //e.Row.Cells["idEmpleado"].Value = 1;
                //e.Row.Cells["idVehiculo"].Value = 1;
                e.Row.Cells["fechaUltimaGestion"].Value = DateTime.Now;
                e.Row.Cells["usuarioUltimaGestion"].Value = BGCOP.CAVTOP.WINFORMS.Program.idUsuarioActual;
            }
            catch (Exception)
            {
                
                //throw;
            }
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ExportToExcelML exporter = new ExportToExcelML(this.radGridView1);
            exporter.HiddenColumnOption = Telerik.WinControls.UI.Export.HiddenOption.DoNotExport;
            exporter.ExportVisualSettings = true;
            exporter.SheetMaxRows = ExcelMaxRows._1048576;
            exporter.SheetName = "Listado";
            exporter.SummariesExportOption = SummariesOption.DoNotExport;
            string ruta;
            ruta = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\ExportedVehiculosAsignados.xls";
            try
            {
                exporter.RunExport(ruta);
                radDesktopAlert1.ContentImage = BGCOP.CAVTOP.WINFORMS.Properties.Resources.File_Excel_icon;
                radDesktopAlert1.CaptionText = "Exportar a excel";
                radDesktopAlert1.ContentText = "El archivo se exportado con exito.\r\nRuta: " + ruta;
                radDesktopAlert1.FixedSize = new Size(450, 150);
                radDesktopAlert1.Show();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
        }

        private void radGridView1_DataError(object sender, Telerik.WinControls.UI.GridViewDataErrorEventArgs e)
        {
            try
            {
                MessageBox.Show("Error: " + e.ToString(), Properties.Settings.Default.Titulo
                                    , MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception)
            {
                
                
            }
        }
    }
}
